
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="title">修改密码</h4>
        </div>
        <div class="modal-body">
            <div class="container-fluid">
                <form id="pwdForm" class="form-horizontal">
                    <input type="hidden" class="form-control" id="id" name="id"  value="{$userInfo.id}">
                    <div class="form-group">
                        <label for="oldPassword" class="col-sm-2 control-label">原密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="oldPassword" name="oldPassword" placeholder="原密码" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">新密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="password" name="password" placeholder="新密码" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="confirmPassword" class="col-sm-2 control-label">确认新密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" placeholder="确认新密码" >
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" id="pwdBtn">确定</button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

<script>
    $("#pwdForm").validate({
        rules: {
            oldPassword: {
                required: true
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 10
            },
            confirmPassword: {
                required: true,
                equalTo: "#password"
            }
        },
        messages: {
            oldPassword: {
                required: "请输入原密码"
            },
            password: {
                required: "请输入新密码",
                minlength: $.validator.format("新密码不能小于{0}个字符"),
                maxlength: $.validator.format("新密码不能多于{0}个字符")
            },
            confirmPassword: {
                required: "请输入确认密码",
                equalTo: "两次输入密码不一致"
            }
        }
    });
    $("#pwdBtn").on("click",function(){
        if($("#pwdForm").valid()){
            var formData = $("#pwdForm").serialize();
            $.ajax({
                type: "POST",
                dataType: 'json',
                url: "__URL__/updatePwdAjax",
                data: formData,
                success: function onSuccess(data, status)
                {
                    if(data.code > 0 ){
                        alertMsg(data.msg, {icon:'warning'});
                    }
                    else{
                        $("#pwdModal").modal("hide");
                        alertMsg(data.msg, {icon:'succeed'});
                        window.location.href = "__APP__/Auth/logout";
                    }
                },
                error: function onError(data, status)
                {
                    // handle an error
                }
            });
        }
        return false;
    });
</script>        